from flask import Flask
from flask_restful import Resource,Api,inputs
from flask_restful.reqparse import RequestParser

app = Flask(__name__)
api = Api(app)

class RegisterView(Resource):
    def post(self):
        #建立解析器
        parser = RequestParser()
        #定义数据解析规则
        parser.add_argument('uname',type=str,required=True,trim=True,help='用户名不规范')
        parser.add_argument('pwd',type=str,help='密码不规范')
        parser.add_argument('age',type=int,help='年龄不规范')
        parser.add_argument('gender',type=str,choices=['男','女','未知'],help='姓名验证错误')
        parser.add_argument('birthday',type=inputs.date,help='生日验证错误')
        parser.add_argument('phone',type=inputs.regex('^1[3456789]\d{9}$'),help='电话验证错误')
        parser.add_argument('homepage',type=inputs.url,help='个人主页验证错误')
        #解析数据
        args = parser.parse_args()
        print(args)
        #响应数据
        return {'msg':'注册成功'}

api.add_resource(RegisterView,'/register/')

if __name__ == '__main__':
    app.run(debug=True)